from PyQt5 import QtCore
import decimal
import logging

config=None
mainw=None
server=None
class MySet:
    def __init__(self):
        self._data=[]
    def count(self,v):
        if v in self._data:
            return 1
        return 0
    def erase(self,v):
        self._data.remove(v)
        pass
    def insert(self,v):
        logging.info([v,self._data])
        if v in self._data:
            logging.info("already in")
            pass
        else:
            self._data.append(v)
            self._data.sort()
            logging.info(self._data)
    def size(self):
        return len(self._data)
    def empty(self):
        if len(self._data)==0:
            return True
        else:
            return False
    def begin(self):
        return self._data[0]
    def at(self,i):
        return self._data[i]
    def end(self):
        return self._data[len(self._data)-1]
    def rbegin(self):
        return self.end()
    def rend(self):
        return self.begin()
    def clear(self):
        self._data=[]
    pass
def timestr():
    db = QtCore.QDateTime.currentDateTime()
    db_str = db.toString("yyyy_MM_dd_hh_mm_ss")
    return db_str
def in_list(one, l1):
    for i in range(len(l1)):
        # logging.info(str(one)+str(l1[i]))
        if one in l1[i]:
            return i
    return -1
def myfloat(f):
    try:
        r = float(f)
    except ValueError:
        r = 0
    except TypeError:
        r=0
    return r
def is_float(a_string):
    try:
        float(a_string)
        return True
    except TypeError:
        return False
    except ValueError:
        return False    
def isfloat(f):
    try:
        r = float(f)
        return True
    except ValueError:
        return False
def inItems(items, one):
    for s in items:
        if s[0] == one[0] and s[1] == one[1]:
            return True
    return False    
def isDev():
    try:
        from getmac import get_mac_address
        mac=get_mac_address()
        print(mac)
        if mac in ['00:e1:8c:ea:99:5d']:
            return True
        else:
            return False    
    except ModuleNotFoundError:
        return False

def valid_count(num_str,p):
    if num_str=="":
        return ""
    d=decimal.Context(prec=p,rounding=decimal.ROUND_HALF_EVEN).create_decimal(num_str)
    d=remove_exponent(d)
    r=str(d)
    return r
def point_count(num_str,p):
    if num_str=="":
        return ""
    zstr="0."+p*"0"
    logging.info([num_str,p,zstr])
    d=decimal.Decimal(num_str).quantize(decimal.Decimal(zstr),rounding=decimal.ROUND_HALF_EVEN)
    d=remove_exponent(d)
    r=str(d)
    return r
def remove_exponent(d):
    return d.quantize(decimal.Decimal(1)) if d == d.to_integral() else d.normalize()
def ppmTopc(ppmstr):
    d=decimal.Decimal(ppmstr)
    d=d/10000
    print(dir(d))
    d=remove_exponent(d)
    r=str(d)
    return r
if __name__=="__main__":
    print(ppmTopc("3.12"))